﻿using System;
using System.Drawing;
using DevExpress.XtraEditors;
using Shell.Events;

namespace Shell
{
    public class ViewBase : XtraForm, IView
    {
        protected bool IsActive { get; set; }

        public Guid Id { get; set; }

        private string m_Caption;
        public string Caption
        {
            get { return m_Caption; }
            set
            {
                m_Caption = value;
                Text = value;
            }
        }

        public event EventHandler<EventArg<string>> StatusChanged;
        
        public event EventHandler<AlertEventArgs> AlertChanged;

        public void OnAlertChanged(AlertEventArgs e)
        {
            EventHandler<AlertEventArgs> handler = AlertChanged;
            if (handler != null) handler(this, e);
        }

        protected void OnStatusChanged(string statusMessage)
        {
            EventHandler<EventArg<string>> handler = StatusChanged;
            if (handler != null) handler(this, new EventArg<string>(statusMessage));
        }

        public virtual void OnNew()
        {
            OnAlertChanged(new AlertEventArgs("Opcija nije dostupna"));
        }

        public virtual void OnSave()
        {
            OnAlertChanged(new AlertEventArgs("Opcija nije dostupna"));
        }

        public virtual void OnRefresh()
        {
            OnAlertChanged(new AlertEventArgs("Opcija nije dostupna"));
        }

        public virtual void OnDelete()
        {
            OnAlertChanged(new AlertEventArgs("Opcija nije dostupna"));
        }

        public virtual void OnSearch()
        {
            OnAlertChanged(new AlertEventArgs("Opcija nije dostupna"));
        }

        protected override void OnActivated(EventArgs e)
        {
            IsActive = true;
            base.OnActivated(e);
        }

        protected override void OnDeactivate(EventArgs e)
        {
            IsActive = false;
            base.OnDeactivate(e);
        }
    }
}